# -*- coding:utf-8 -*-
#! python3
from facecat import *
#这里可能需要pip install requests
import requests
from requests.adapters import HTTPAdapter
import random
from datetime import datetime
import timer

#更新悬浮状态
#views:视图集合
def updateView(views):
	updateViewDefault(views)

#绘制视图
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaint(view, paint, clipRect):
	onPaintDefault(view, paint, clipRect)
	if view.viewType == "buysell":
		drawBuySellDiv(view, paint, clipRect)

#绘制视图边线
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaintBorder(view, paint, clipRect):
	onPaintBorderDefault(view, paint, clipRect)

#视图的鼠标移动方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseMove(view, mp, buttons, clicks, delta):
	onMouseMoveDefault(view, mp, buttons, clicks, delta)
		
#视图的鼠标按下方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseDown(view, mp, buttons, clicks, delta):
	if view.viewType == "chart":
		if len(view.data) == 0:
			return
		if len(view.addingPlot) > 0:
			addPlotDefault(view, True, mp, False, mp)
			view.addingPlot = ""
			invalidateView(chart)
		else:
			touchDownChart(view, True, mp, False, mp)
			invalidateView(chart)
	else:
		onMouseDownDefault(view, mp, buttons, clicks, delta)

#视图的鼠标抬起方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseUp(view, mp, buttons, clicks, delta):
	onMouseUpDefault(view, mp, buttons, clicks, delta)

#视图的鼠标点击方法
#view 视图
#firstTouch:是否第一次触摸 
#firstPoint:第一次触摸的坐标 
#secondTouch:是否第二次触摸 
#secondPoint:第二次触摸的坐标
#clicks 点击次数
def onClick(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks):
	onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)
	global gPaint
	global currentCycle
	global chart
	if view.viewName == "btnCycleDay":
		chart.cycle = "day"
		currentCycle = "day"
		if gPaint.onPaintChartHScale == None:
			gPaint.onPaintChartHScale = drawChartHScale
		queryHistoryData()
	elif view.viewName == "btnCycleTime":
		chart.cycle = "trend"
		currentCycle = "time"
		if gPaint.onPaintChartHScale != None:
			gPaint.onPaintChartHScale = None
		queryHistoryData()
	elif view.viewName == "btnType1":
		tabType = findViewByName("tabType", gPaint.views)
		selectTabPage(tabType, tabType.tabPages[0])
		invalidateView(tabType)
	elif view.viewName == "btnType2":
		tabType = findViewByName("tabType", gPaint.views)
		selectTabPage(tabType, tabType.tabPages[1])
		invalidateView(tabType)
	elif view.viewName == "btnType3":
		tabType = findViewByName("tabType", gPaint.views)
		selectTabPage(tabType, tabType.tabPages[2])
		invalidateView(tabType)
	elif len(view.viewName) > 0:
		if view.viewName.find("Indicator_") == 0:
			if view.text == "BOLL" or view.text == "MA":
				chart.mainIndicator = view.text
			else:
				chart.showIndicator = view.text
			calcChartIndicator(chart)
			invalidateView(chart)
		elif view.viewName.find("Plot_") == 0:
			chart.addingPlot = view.viewName[5:]
		
#视图的鼠标滚动方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
def onMouseWheel(view, mp, buttons, clicks, delta):
	onMouseWheelDefault(view, mp, buttons, clicks, delta)

#请求历史数据
def queryHistoryData():
	global chart
	try:
		url = "https://web.ifzq.gtimg.cn/appstock/app/fqkline/get?_var=kline_dayqfq&param=sh601857,day,,,320,qfq&r=0.9860043111257255"
		if currentCycle == "time":
			url = "https://web.ifzq.gtimg.cn/appstock/app/minute/query?code=sh601857"
		s = requests.Session()
		s.mount('http://', HTTPAdapter(max_retries=3))
		response = s.get(url)
		result = response.text
		if chart.cycle == "trend":
			chart.autoFillHScale = True
		else:
			chart.autoFillHScale = False
		chart.hScalePixel = 11
		dataList = []
		if chart.cycle == "trend":
			idx1 = result.find("\"data\":[\"")
			result = result[idx1 + len("\"data\":[\""):]
			idx2 = result.find("\"]")
			result = result[0:idx2]
			datas = result.split(",")
			lastVolume = 0
			for i in range(0, len(datas)):
				subDatas = datas[i].replace("\"", "").split(" ")
				if len(subDatas) > 2:
					data = SecurityData()
					data.close = float(subDatas[1])
					data.high = float(subDatas[1])
					data.low = float(subDatas[1])
					data.open = float(subDatas[1])
					data.volume = float(subDatas[2]) - lastVolume
					lastVolume = float(subDatas[2])
					dateStr = subDatas[0]
					hourStr = dateStr[0:2]
					minuteStr = dateStr[2:4]
					date_obj = datetime.strptime("1970-01-01 " + hourStr + ":" + minuteStr + ":00", "%Y-%m-%d %H:%M:%S")
					data.date = time.mktime(date_obj.timetuple())
					dataList.append(data)
		else:
			datas = result.split("[")
			for i in range(0, len(datas)):
				subDatas = datas[i].split(",")
				if len(subDatas) == 7:
					data = SecurityData()
					dateStr = subDatas[0].replace("'", "").replace("\"", "")
					date_obj = datetime.strptime(dateStr, "%Y-%m-%d")
					date = time.mktime(date_obj.timetuple())
					data.close = float(subDatas[2].replace("'", "").replace("\"", ""))
					data.high = float(subDatas[3].replace("'", "").replace("\"", ""))
					data.low = float(subDatas[4].replace("'", "").replace("\"", ""))
					data.open = float(subDatas[1].replace("'", "").replace("\"", ""))
					data.volume = float(subDatas[5].replace("'", "").replace("\"", "").replace("]", ""))
					data.date = date
					dataList.append(data)
		chart.data = dataList
		maxVisibleRecord = getChartMaxVisibleCount(chart, chart.hScalePixel, getChartWorkAreaWidth(chart))
		chart.lastVisibleIndex = len(chart.data) - 1
		if maxVisibleRecord > len(chart.data):
			chart.firstVisibleIndex = 0
		else:
			chart.firstVisibleIndex = chart.lastVisibleIndex - maxVisibleRecord + 1
		resetChartVisibleRecord(chart)
		checkChartLastVisibleIndex(chart)
		calcChartIndicator(chart)
		invalidateView(chart)
	except requests.exceptions.RequestException as e:
			print(e)

#查询最新数据
def queryLatestData(a='', b=''):
	global chart
	global latestDataStr
	try:
		url = "http://qt.gtimg.cn/q=sh601857"
		s = requests.Session()
		s.mount('http://', HTTPAdapter(max_retries=3))
		response = s.get(url)
		result = response.text
		latestDataStr = result
		buySellView = findViewByName("buySellDiv", gPaint.views)
		invalidateView(buySellView)
		gridPrice = findViewByName("gridPrice", gPaint.views)
		gridPrice.rowHeight = 20
		row = FCGridRow()
		gridPrice.rows.insert(0, row)
		cell = FCGridCellEx()
		row.cells.append(cell);
		dataStrs = latestDataStr.split("~")
		cell.price = float(dataStrs[9])
		cell.volume = math.floor(random.randint(0, 50)) + 1
		if math.floor(random.randint(0, 2)) == 0:
			cell.direction = "B"
		else:
			cell.direction = "S"
		cell.time = dataStrs[30]
		cell.closePrice = float(dataStrs[3])
		invalidateView(gridPrice)
		if currentCycle == "day":
			dateStr = cell.time[0:8]
			dateStr = dateStr[0:4] + "-" + dateStr[4:6] + "-" + dateStr[6:8]
			date_obj = datetime.strptime(dateStr, "%Y-%m-%d")
			newDate = time.mktime(date_obj.timetuple())
			data = SecurityData()
			data.close = float(dataStrs[3])
			data.high = float(dataStrs[33])
			data.low = float(dataStrs[34])
			data.open = float(dataStrs[5])
			data.volume = float(dataStrs[6])
			data.date = newDate
			if len(chart.data) > 0 and newDate == chart.data[len(chart.data) - 1].date:
				chart.data[len(chart.data) - 1] = data
			else:
				chart.data.push(data)
			maxVisibleRecord = getChartMaxVisibleCount(chart, chart.hScalePixel, getChartWorkAreaWidth(chart))
			chart.lastVisibleIndex = len(chart.data) - 1
			if maxVisibleRecord > len(chart.data):
				chart.firstVisibleIndex = 0
			else:
				chart.firstVisibleIndex = chart.lastVisibleIndex - maxVisibleRecord + 1
			resetChartVisibleRecord(chart)
			checkChartLastVisibleIndex(chart)
			calcChartIndicator(chart)
			invalidateView(chart)
	except requests.exceptions.RequestException as e:
			print(e)

#绘制买卖档
#view:视图
#paint:绘图对象
#clipRect:区域
def drawBuySellDiv(view, paint, clipRect):
	avgHeight = view.size.cy / 10
	drawFont = "Default,14"
	dTop = 0
	dataStrs = latestDataStr.split("~")
	closePrice = 0
	priceList = []
	volList = []
	buySellTexts = []
	if len(dataStrs) > 80:
		closePrice = float(dataStrs[3])
		priceList.append(float(dataStrs[27]))
		priceList.append(float(dataStrs[25]))
		priceList.append(float(dataStrs[23]))
		priceList.append(float(dataStrs[21]))
		priceList.append(float(dataStrs[19]))
		priceList.append(float(dataStrs[9]))
		priceList.append(float(dataStrs[11]))
		priceList.append(float(dataStrs[13]))
		priceList.append(float(dataStrs[15]))
		priceList.append(float(dataStrs[17]))

		volList.append(float(dataStrs[28]))
		volList.append(float(dataStrs[26]))
		volList.append(float(dataStrs[24]))
		volList.append(float(dataStrs[22]))
		volList.append(float(dataStrs[20]))
		volList.append(float(dataStrs[10]))
		volList.append(float(dataStrs[12]))
		volList.append(float(dataStrs[14]))
		volList.append(float(dataStrs[16]))
		volList.append(float(dataStrs[18]))

	buySellTexts.append("卖5")
	buySellTexts.append("卖4")
	buySellTexts.append("卖3")
	buySellTexts.append("卖2")
	buySellTexts.append("卖1")
	buySellTexts.append("买1")
	buySellTexts.append("买2")
	buySellTexts.append("买3")
	buySellTexts.append("买4")
	buySellTexts.append("买5")
	textColor = "rgb(200,200,200)"
	if view.paint.defaultUIStyle == "light":
		textColor = "rgb(0,0,0)"
	maxVol = maxValue(volList)
	for i in range(0, 10):
		tSize = paint.textSize(buySellTexts[i], drawFont)
		paint.drawText(buySellTexts[i], textColor, drawFont, 5, dTop + avgHeight / 2 - tSize.cy / 2)
		if len(priceList) > 0:
			price = priceList[i]
			upDownColor = "rgb(255,0,0)"
			upDownColor2 = "rgba(255,0,0,50)"
			if price >= closePrice:
				upDownColor = "rgb(255,0,0)"
				upDownColor2 = "rgba(255,0,0,50)"
			elif price < closePrice:
				upDownColor = "rgb(0,255,0)"
				upDownColor2 = "rgba(0,255,0,50)"
			paint.drawText(toFixed(priceList[i], 2), upDownColor, drawFont, 50, dTop + avgHeight / 2 - tSize.cy / 2)
			if maxVol > 0:
				paint.fillRect(upDownColor2, view.size.cx - volList[i] * 80 / maxVol, dTop + 2, view.size.cx, dTop + avgHeight - 2)
			volText = toFixed(volList[i], 0)
			volTextSize = paint.textSize(volText, drawFont)
			paint.drawText(toFixed(volList[i], 0), textColor, drawFont, view.size.cx - volTextSize.cx - 10, dTop + avgHeight / 2 - volTextSize.cy / 2)
		dTop += avgHeight

#黑色风格
def toBlack_Chart():
	global chart
	chart.paint.defaultUIStyle = "dark"
	chart.backColor = "rgb(0,0,0)"
	chart.borderColor = "rgb(100,100,100)"
	chart.textColor = "rgb(255,255,255)"
	chart.scaleColor = "rgb(100,100,100)"
	chart.crossTipColor = "rgb(50,50,50)"
	chart.crossLineColor = "rgb(100,100,100)"
	chart.gridColor = "rgba(100,100,100,125)"
	chart.indicatorColors = []
	chart.indicatorColors.append("rgb(255,255,255)")
	chart.indicatorColors.append("rgb(255,255,0)")
	chart.indicatorColors.append("rgb(255,0,255)")
	chart.indicatorColors.append("rgb(255,0,0)")
	chart.indicatorColors.append("rgb(0,255,255)")
	chart.indicatorColors.append("rgb(0,255,0)")
	chart.indicatorColors.append("rgb(255,255,0)")
	chart.indicatorColors.append("rgb(255,255,255)")
	for i in range(0, len(chart.plots)):
		plot = chart.plots[i]
		plot.lineColor = "rgb(255,255,255)"
		plot.pointColor = "rgba(255,255,255,125)"

#白色风格
def toWhite_Chart():
	global chart
	chart.paint.defaultUIStyle = "light"
	chart.backColor = "rgb(255,255,255)"
	chart.borderColor = "rgb(150,150,150)"
	chart.textColor = "rgb(0,0,0)"
	chart.scaleColor = "rgb(0,0,0)"
	chart.crossTipColor = "rgb(220,220,220)"
	chart.crossLineColor = "rgb(100,100,100)"
	chart.gridColor = "rgba(0,0,0,125)"
	chart.indicatorColors = []
	chart.indicatorColors.append("rgb(100,100,100)")
	chart.indicatorColors.append("rgb(206,147,27)")
	chart.indicatorColors.append("rgb(150,0,150)")
	chart.indicatorColors.append("rgb(255,0,0)")
	chart.indicatorColors.append("rgb(0,150,150)")
	chart.indicatorColors.append("rgb(0,150,0)")
	chart.indicatorColors.append("rgb(59,174,218)")
	chart.indicatorColors.append("rgb(50,50,50)")
	chart.vice
	for i in range(0, len(chart.plots)):
		plot = chart.plots[i]
		plot.lineColor = "rgb(0,0,0)"
		plot.pointColor = "rgba(0,0,0,125)"

#单元格
class FCGridCellEx(FCGridCell):	
	def __init__(self):
		super().__init__()
		self.time = "" #时间
		self.price = 0 #价格
		self.volume = 0 #量
		self.direction = "B" #方向
		self.closePrice = 0 #当时的收盘价

#绘制单元格
#grid:表格
#row:行
#column:列
#cell:单元格
#paint:绘图对象
#left:左侧坐标
#top:上方坐标
#right:右侧坐标
#bottom:下方坐标
def onPaintGridCell(grid, row, column, cell, paint, left, top, right, bottom):
	if grid.viewName == "gridPrice":
		drawTime = cell.time[8:]
		drawTime = drawTime[0:2] + ":" + drawTime[2:4]
		drawFont = "Default,14"
		textColor = "rgb(200,200,200)"
		if grid.paint.defaultUIStyle == "light":
			textColor = "rgb(0,0,0)"
		tSize = paint.textSize(drawTime, drawFont)
		paint.drawText(drawTime, textColor, drawFont, 5, top + (bottom - top - tSize.cy) / 2)
		if cell.price >= cell.closePrice:
			paint.drawText(toFixed(cell.price, 2), "rgb(255,0,0)", drawFont, 50, top + (bottom - top - tSize.cy) / 2)
		else:
			paint.drawText(toFixed(cell.price, 2), "rgb(0,255,0)", drawFont, 50, top + (bottom - top - tSize.cy) / 2)
		if cell.direction == "B":
			paint.drawText(cell.direction, "rgb(255,0,0)", drawFont, grid.size.cx - 20, top + (bottom - top - tSize.cy) / 2)
		elif cell.direction == "S":
			paint.drawText(cell.direction, "rgb(0,255,0)", drawFont, grid.size.cx - 20, top + (bottom - top - tSize.cy) / 2)
		volTextSize = paint.textSize(toFixed(cell.volume, 0), drawFont)
		paint.drawText(toFixed(cell.volume, 0), textColor, drawFont, grid.size.cx - 22 - volTextSize.cx, top + (bottom - top - volTextSize.cy) / 2)
	else:
		drawGridCell(grid, row, column, cell, paint, left, top, right, bottom)

#绘制横轴刻度的自定义方法
#chart:图表
#paint:绘图对象
#clipRect:裁剪区域
#该逻辑仅针对日K线
def drawChartHScale(chart, paint, clipRect):
	#判断数据是否为空
	if chart.data != None and len(chart.data) > 0 and chart.hScaleHeight > 0:
		drawLeft = chart.leftVScaleWidth #左侧起画点
		i = chart.firstVisibleIndex #开始索引
		lastYear = 0 #缓存年份，用于判断是否换年
		drawYearsCache = [] #实际绘制到图形上的年份文字
		lastTextRight = 0 #上个文字的右侧
		timeCache = [] #保存日期的缓存
		yearTextLeftCache = [] #绘制年文字的左侧位置缓存
		yearTextRightCache = [] #绘制年文字的右侧位置缓存
		textPadding = 5 #两个文字之间的最小间隔
		#逐步递增索引，先绘制年
		while i <= chart.lastVisibleIndex:
			dateObj = time.localtime(chart.data[i].date) #将时间戳转换为time，并缓存到集合中
			timeCache.append(dateObj)
			year = dateObj.tm_year #从结构中获取年份			
			x = getChartX(chart, i) #获取索引对应的位置
			#判断是否换年，以及是否在绘图区间内
			if year != lastYear and x >= drawLeft and x < chart.size.cx - chart.rightVScaleWidth:
				month = dateObj.tm_mon #获取月的结构
				xText = str(year) #拼接要绘制的文字
				if month < 10:
					xText = xText + "-0" + str(month) #如果小于10月要补0
				else:
					xText = xText + "-" + str(month) #大于等于10月不用补0
				tSize = paint.textSize(xText, chart.font) #计算要绘制文字的大小
				paint.drawLine("rgb(100,100,100)", 1, 0, x, chart.size.cy - chart.hScaleHeight, x, chart.size.cy - chart.hScaleHeight + 8) #绘制刻度线
				#判断是否和上个文字重影
				if x - tSize.cx / 2 > lastTextRight + textPadding:
					paint.drawText(xText, "rgb(200,200,200)", "Default,12", x - tSize.cx / 2, chart.size.cy - chart.hScaleHeight + 8  - tSize.cy / 2 + 7) #绘制文字
					yearTextLeftCache.append(x - tSize.cx / 2) #将年文字的左侧位置缓存
					yearTextRightCache.append(x + tSize.cx / 2) #将年文字的右侧位置缓存
					drawYearsCache.append(year) #缓存要绘制的年
					lastTextRight = x + tSize.cx / 2 #缓存上个文字的右侧位置
				lastYear = year #记录上次绘制的年份
			i = i + 1	#索引累加	
		#绘制月份
		for m in range(0, len(drawYearsCache)):
			cacheYear = drawYearsCache[m] #从缓存中获取年份
			lastMonth = 0 #缓存月份，用于判断是否换月
			i = chart.firstVisibleIndex #重置开始索引
			lastTextRight = 0 #重置上个文字的右侧
			#逐步递增索引
			while i <= chart.lastVisibleIndex:
				dateObj = timeCache[i - chart.firstVisibleIndex] #从缓存中获取time
				year = dateObj.tm_year #从结构中获取年份
				#判断是否同一年	
				if cacheYear == year:
					month = dateObj.tm_mon #从结构中获取月份
					x = getChartX(chart, i)
					#判断是否换月，以及是否在绘图区间内
					if lastMonth != month and x >= drawLeft and x < chart.size.cx - chart.rightVScaleWidth:			
						xText = str(month) #获取绘制的月份文字
						tSize = paint.textSize(xText, chart.font) #计算要绘制文字的大小
						#判断是否和上个文字重影
						if x - tSize.cx / 2 > lastTextRight + textPadding:
							#判断是否和年的文字重影
							if (x - tSize.cx / 2 > yearTextRightCache[m] + textPadding) and ((m == len(drawYearsCache) - 1) or (m < len(drawYearsCache) - 1 and x + tSize.cx / 2 < yearTextLeftCache[m + 1] - textPadding)):
								paint.drawLine("rgb(100,100,100)", 1, 0, x, chart.size.cy - chart.hScaleHeight, x, chart.size.cy - chart.hScaleHeight + 6) #绘制刻度
								paint.drawText(xText, "rgb(200,200,200)", "Default,12", x - tSize.cx / 2, chart.size.cy - chart.hScaleHeight + 8  - tSize.cy / 2 + 7) #绘制文字
								lastTextRight = x + tSize.cx / 2 #缓存上个文字的右侧位置
						lastMonth = month #记录上次绘制的月份
				elif cacheYear < year:
					break #超过区间，退出循环
				i = i + 1	#索引累加


gPaint = FCPaint() #创建绘图对象
gPaint.defaultUIStyle = "dark"
gPaint.onPaint = onPaint 
gPaint.onPaintBorder = onPaintBorder
gPaint.onMouseDown = onMouseDown 
gPaint.onMouseMove = onMouseMove 
gPaint.onMouseUp = onMouseUp
gPaint.onMouseWheel = onMouseWheel
gPaint.onClick = onClick
gPaint.onUpdateView = updateView
gPaint.onPaintGridCell = onPaintGridCell
gPaint.onPaintChartHScale = drawChartHScale #注册重绘横轴的事件

latestDataStr = ""
currentCycle = ""

#消息循环
def WndProc(hwnd,msg,wParam,lParam):
	return WndProcDefault(gPaint,hwnd,msg,wParam,lParam)

#初始化窗体
createMainWindow(gPaint, "facecat-py", WndProc)
gPaint.init()
gPaint.allowPartialPaint = False
gPaint.systemFont = "SimSun"
gPaint.gdiPlusPaint.encoding = "utf-8"
xml = """<?xml version="1.0" encoding="utf-8"?>
<html xmlns="facecat">
	<head>
	</head>
	<body>
	<div type="splitlayout" layoutstyle="toptobottom" bordercolor="none" dock="fill" size="400,400" candragsplitter="true" splitterposition="25,0">
		<div type="layout" backcolor="none" bordercolor="none">
		<input type="button" text="分时" size="80,25" name="btnCycleTime" />
		<input type="button" text="日线" size="80,25" name="btnCycleDay" />
		<select name="cbIndicator" selectedindex="0" size="80,25">
			<option text="MA" name="Indicator_MA" />
			<option text="BOLL" name="Indicator_BOLL" />
			<option text="MACD" name="Indicator_MACD" />
			<option text="KDJ" name="Indicator_KDJ" />
			<option text="BIAS" name="Indicator_BIAS" />
			<option text="BBI" name="Indicator_BBI" />
			<option text="RSI" name="Indicator_RSI" />
			<option text="ROC" name="Indicator_ROC" />
			<option text="WR" name="Indicator_WR" />
			<option text="DMA" name="Indicator_DMA" />
			<option text="TRIX" name="Indicator_TRIX" />
			<option text="CCI" name="Indicator_CCI" />
		</select>
		<select name="cbPlot" selectedindex="0" size="100,25">
			<option text="直线" name="Plot_Line" />
			<option text="线段" name="Plot_Segment" />
			<option text="射线" name="Plot_Ray" />
			<option text="三角形" name="Plot_Triangle" />
			<option text="矩形" name="Plot_Rect" />
			<option text="圆" name="Plot_Cycle" />
			<option text="外接圆" name="Plot_CircumCycle" />
			<option text="椭圆" name="Plot_Ellipse" />
			<option text="角度线" name="Plot_AngleLine" />
			<option text="线性回归" name="Plot_LRLine" />
			<option text="线性回归通道" name="Plot_LRChannel" />
			<option text="对称三角形" name="Plot_SymmetricTriangle" />
			<option text="线性回归带" name="Plot_LRBand" />
			<option text="平行四边形" name="Plot_ParalleGram" />
			<option text="速阻线" name="Plot_SpeedResist" />
			<option text="斐波扇面" name="Plot_FiboFanline" />
			<option text="斐波周期线" name="Plot_FiboTimezone" />
			<option text="百分比线" name="Plot_Percent" />
			<option text="箱型线" name="Plot_BoxLine" />
			<option text="泰龙水平线" name="Plot_TironeLevels" />
			<option text="四等分线" name="Plot_QuadrantLines" />
			<option text="平行线" name="Plot_Parallel" />
			<option text="黄金分割线" name="Plot_GoldenRatio" />
			<option text="箭头线段" name="Plot_ArrowSegment" />
		</select>
		</div>
		<div type="splitlayout" layoutstyle="righttoleft" bordercolor="none" dock="fill" size="400,400" candragsplitter="true" splitmode="absolutesize" splittervisible="true" splitterposition="200,0" name="splitLeftRight">
		<div type="splitlayout" layoutstyle="toptobottom" bordercolor="none" dock="fill" size="400,400" candragsplitter="true" splitterposition="220,1">
			<input type="custom" cid="buysell" name="buySellDiv" />
			<div type="splitlayout" layoutstyle="toptobottom" bordercolor="none" dock="fill" size="400,400" candragsplitter="true" splitterposition="25,1">
			<div bordercolor="none" backcolor="none">
				<select name="cbType" selectedindex="0" bordercolor="none" size="75,25" align="center" vertical-align="middle">
				<option text="分时成交" name="btnType1" />
				<option text="备用页面" name="btnType2" />
				<option text="备用页面2" name="btnType3" />
				</select>
			</div>
			<div type="tab" backcolor="none" bordercolor="none" name="tabType" selectedindex="0">
				<div type="tabpage" backcolor="none" bordercolor="none" text="分时成交" headersize="0,0">
				<table name="gridPrice" headerheight="0" dock="fill">
					<tr>
					<th width="199" text="Price" />
					</tr>
				</table>
				</div>
				<div type="tabpage" backcolor="none" bordercolor="none" text="备用页面" headersize="0,0" />
				<div type="tabpage" backcolor="none" bordercolor="none" text="备用页面2" headersize="0,0" />
			</div>
			</div>
		</div>
		<div name="div1">
			<chart size="200,200" name="Chart" text="Chart" dock="Fill">
			</chart>
		</div>
		</div>
	</div>
	</body>
</html>"""
renderFaceCat(gPaint, xml)
chart = findViewByName("Chart", gPaint.views)
chart.mainIndicator = "BOLL"
chart.showIndicator = "BIAS"
chart.plotPointSizeChart = 15
chart.leftVScaleWidth = 70
chart.rightVScaleWidth = 70
chart.vScaleDistance = 35
chart.hScalePixel = 11
chart.hScaleHeight = 35
chart.candlePaddingTop = 30
chart.candlePaddingBottom = 20
chart.volPaddingTop = 20
chart.volPaddingBottom = 0
chart.indPaddingTop = 20
chart.indPaddingBottom = 20
chart.vScaleDistance = 35
chart.cycle = "day"
chart.font = "Default,12"
if gPaint.defaultUIStyle == "dark":
	toBlack_Chart()
elif gPaint.defaultUIStyle == "light":
	toWhite_Chart()
invalidateView(chart)
queryHistoryData()
queryLatestData()
#启动秒表
timer.set_timer(1000, queryLatestData)
showWindow(gPaint)